home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2001 December / pcwk12201b.iso / Wersje pelne i specjalne / Winamp 2.77 i 3.0beta / wasabi-sdk_beta1.exe / studio / common / clickwnd.cpp < prev    next >
C/C++ Source or Header  |  2001-10-08  |  5KB  |  198 lines

  1. /*
  2.  
  3.   Nullsoft WASABI Source File License
  4.  
  5.   Copyright 1999-2001 Nullsoft, Inc.
  6.  
  7.     This software is provided 'as-is', without any express or implied
  8.     warranty.  In no event will the authors be held liable for any damages
  9.     arising from the use of this software.
  10.  
  11.     Permission is granted to anyone to use this software for any purpose,
  12.     including commercial applications, and to alter it and redistribute it
  13.     freely, subject to the following restrictions:
  14.  
  15.     1. The origin of this software must not be misrepresented; you must not
  16.        claim that you wrote the original software. If you use this software
  17.        in a product, an acknowledgment in the product documentation would be
  18.        appreciated but is not required.
  19.     2. Altered source versions must be plainly marked as such, and must not be
  20.        misrepresented as being the original software.
  21.     3. This notice may not be removed or altered from any source distribution.
  22.  
  23.  
  24.   Brennan Underwood
  25.   brennan@nullsoft.com
  26.  
  27. */
  28.  
  29.  
  30. #include "clickwnd.h"
  31.  
  32. #include "../studio/api.h"
  33.  
  34. ClickWnd::ClickWnd() {
  35.   handleRight = TRUE;
  36.   button = -1;
  37.   mousedown = 0;
  38.   captured = 0;
  39.   hilite = 0;
  40.   down = 0;
  41. }
  42.  
  43. void ClickWnd::setHandleRightClick(int tf) {
  44.   handleRight=tf;
  45. }
  46.  
  47. int ClickWnd::getHandleRightClick() {
  48.   return handleRight;
  49. }
  50.  
  51. int ClickWnd::onLeftButtonDown(int x, int y) {
  52.   CLICKWND_PARENT::onLeftButtonDown(x, y);
  53.   abortTip();
  54.   if (mouseInRegion(x, y))
  55.     return onButtonDown(WM_LBUTTONDOWN, x, y);
  56.   else
  57.     return 1;
  58. }
  59.  
  60. int ClickWnd::onRightButtonDown(int x, int y) {
  61.   CLICKWND_PARENT::onRightButtonDown(x, y);
  62.   abortTip();
  63.   if (!handleRight) return 1;
  64.   if (mouseInRegion(x, y))
  65.     return onButtonDown(WM_RBUTTONDOWN, x, y);
  66.   else
  67.     return 1;
  68. }
  69.  
  70. int ClickWnd::onLeftButtonUp(int x, int y) {
  71.   CLICKWND_PARENT::onLeftButtonUp(x, y);
  72. //jf
  73. //  if (mouseInRegion())
  74.     return onButtonUp(WM_LBUTTONUP, x, y);
  75. //  else
  76. //    return 1;
  77. }
  78.  
  79. int ClickWnd::onRightButtonUp(int x, int y) {
  80.   CLICKWND_PARENT::onRightButtonUp(x, y);
  81.   //jf
  82.   //if (mouseInRegion()) 
  83.   if (!handleRight) {
  84.     onRightPush(x, y);
  85.     return 1;
  86.   }
  87.     return onButtonUp(WM_RBUTTONUP, x, y);
  88. //  else
  89. //    return 1;
  90. }
  91.  
  92. int ClickWnd::onMouseMove(int x, int y) {
  93.   POINT pos, rpos={x,y};
  94.   int mouseover;
  95.  
  96.   CLICKWND_PARENT::onMouseMove(x, y);
  97.  
  98.   pos=rpos;
  99.   clientToScreen(&pos);
  100.  
  101.   mouseover = (api->rootWndFromPoint(&pos) == static_cast<RootWnd *>(this) && mouseInRegion(x, y));
  102.  
  103.   if (!mouseover && (!mousedown || !Std::keyDown(button?MK_RBUTTON:MK_LBUTTON)))
  104.   {
  105.     onLeaveArea();
  106.     endCapture();
  107.     down = 0;
  108.     mousedown = 0;
  109.     captured = 0;
  110.     hilite = 0;
  111.     invalidate();
  112.     return 1;
  113.   }
  114.  
  115.   if (!getCapture() && mouseover) {    // capture to see when leave
  116.     onEnterArea();
  117.     beginCapture();
  118.     captured = 1;
  119.   }
  120.  
  121.   int lastdown = down;
  122.   int lasthilite = hilite;
  123.   hilite = mouseover;
  124.   down = userDown() || (mouseover && mousedown);
  125.   if (down != lastdown || hilite != lasthilite) invalidate();
  126.  
  127.   return 1;
  128. }
  129.  
  130. int ClickWnd::onButtonDown(int which, int x, int y) {
  131.   
  132.   if (!wantClicks()) return 1;
  133.  
  134.   if (!getCapture()) {
  135.     beginCapture();
  136.     captured = 1;
  137.   }
  138.   mousedown = 1;
  139.   down = 1;
  140.   button = -1;
  141.   if (which == WM_LBUTTONDOWN) button = 0;
  142.   else if (which == WM_RBUTTONDOWN) button = 1;
  143.   invalidate();
  144.  
  145.   return 1;
  146. }
  147.  
  148. int ClickWnd::onButtonUp(int which, int x, int y) {
  149.  
  150.     // make sure same button
  151.   if (button == 0 && which == WM_RBUTTONUP) return 1;
  152.   if (button == 1 && which == WM_LBUTTONUP) return 1;
  153.  
  154.   if (!down) {
  155.     onLeaveArea();
  156.     endCapture();
  157.     captured = 0;
  158.     hilite = 0;
  159.     mousedown = 0;
  160.     return 1;
  161.   }
  162.  
  163.     POINT pos={x,y};
  164.     clientToScreen(&pos);
  165.  
  166.     int mouseover = (api->rootWndFromPoint(&pos) == (RootWnd *)this && mouseInRegion(x, y));
  167.     if (!mouseover && captured) {
  168.       onLeaveArea();
  169.       endCapture();
  170.       captured = 0;
  171.       hilite = 0;
  172.     }
  173.  
  174.     // it was down, process the event
  175.     int a = down;
  176.     down = 0;
  177.     mousedown = 0;
  178.     invalidate();
  179.  
  180.     if (a) {
  181.       if (button == 0) onLeftPush(x, y);
  182.       else if (button == 1) onRightPush(x, y);
  183.     } else {        // was off button
  184.       captured = 0;
  185.       hilite = 0;
  186.     }
  187.  
  188.     return 1;
  189. }
  190.  
  191. void ClickWnd::onSetVisible(int show) {
  192.   CLICKWND_PARENT::onSetVisible(show);
  193.   if (!show && getCapture()) {
  194.     endCapture();
  195.     onLeaveArea();
  196.   }
  197. }
  198.